package com.ilock.action;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.ilock.bean.Iuser;
import com.ilock.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;

public class RegisterAction extends ActionSupport{
	
	private IUserService IUserService;
	private Map<String, Object> registerMap;
	private String useremail;
	private String userpassword;
	private String userphoneNumber;
	private String userwechat;
	
	public void setIUserService(IUserService IUserService){
		this.IUserService = IUserService;
	}
	

	public Map getRegisterMap() {
		return registerMap;
	}



	public void setRegisterMap(Map registerMap) {
		this.registerMap = registerMap;
	}


	
	
	public String getUseremail() {
		return useremail;
	}


	public void setUseremail(String useremail) {
		this.useremail = useremail;
	}


	public String getUserpassword() {
		return userpassword;
	}


	public void setUserpassword(String userpassword) {
		this.userpassword = userpassword;
	}


	public String getUserphoneNumber() {
		return userphoneNumber;
	}


	public void setUserphoneNumber(String userphoneNumber) {
		this.userphoneNumber = userphoneNumber;
	}


	public String getUserwechat() {
		return userwechat;
	}


	public void setUserwechat(String userwechat) {
		this.userwechat = userwechat;
	}


	public String execute()throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		if(IUserService.checkIfExist(useremail)){
			Iuser iuser = IUserService.createUser(useremail, userpassword, userphoneNumber, userwechat);
			map.put("user", iuser);
			map.put("state", "registerSuccess");
		}else{
			map.put("state", "emailAlreadyExist");
		}
		this.setRegisterMap(map);
		return "success";
		
	}
	

}
